/**
 * 版权所有 2009-2012山东新北洋信息技术股份有限公司
 * 保留所有权利。
 */
package com.linyaonan.leetcode.medium._1381;

import java.util.ArrayList;

/**
 * @ProjectName: leetcode
 * @Package: com.linyaonan.leetcode.medium._1381
 * @ClassName: CustomStack
 * @Author: linyaonan
 * @Date: 2020/3/26 16:45
 */
public class CustomStack {

    private static int MAX_SIZE;

    private static ArrayList<Integer> add = new ArrayList<>();

    public CustomStack(int maxSize) {
        MAX_SIZE = maxSize;
        add = new ArrayList<>();
    }

    public void push(int x) {
        // 这时才可以插入
        if (add.size() < MAX_SIZE) {
            add.add(x);
        }
    }

    public int pop() {
        if (add.size() == 0) {
            return -1;
        } else {
            return add.remove(add.size() - 1);
        }
    }

    public void increment(int k, int val) {
        for (int i = 0; i < k && i < add.size(); i++) {
            Integer v = add.get(i);
            add.set(i, v + val);
        }
    }

}
